Onion.widget.AudioControl = function(jwin, parent, controlid) {
    Onion.widget.Control.apply(this, arguments);
    this.name = "audiocontrol"
}

Onion.widget.AudioControl.prototype = new Onion.widget.Control();

Onion.widget.AudioControl.prototype.create = function(data) {
    var controlid = "ctrl"+this.controlid;

    this.jwin.factory.append('<audio id="' + controlid + '" src="' + data.src + '" controls autobuffer></audio>');
    this.control = $("#"+controlid);
    this.control.addClass(this.cssclass);
    this.control.addClass(this.name);

    this.control.bind("ended", 
      (function(self) {
        return function() {
            self.ended();
            self.jwin.flush();
        }
      })(this));

    this.control.get(0).autobuffer = true;
    this.control.get(0).preload = 'auto';


}

Onion.widget.AudioControl.prototype.load = function(url) {
    this.control.attr('src', url);
    this.control.get(0).load();
}

Onion.widget.AudioControl.prototype.play = function() {
    this.control.get(0).play();
}
Onion.widget.AudioControl.prototype.pause = function() {
    this.control.get(0).pause();
}

Onion.widget.AudioControl.prototype.ended = function() {
    // invoked when the current song has ended playing
    this.jwin.add_task("event", "ended", this.controlid);
}

Onion.widget.register('audiocontrol', Onion.widget.AudioControl);
